package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Handler;
import android.os.Message;
import android.widget.FrameLayout;
import android.graphics.drawable.Drawable;
public class UC3 extends AppCompatActivity {

    FrameLayout frame = null;
    Handler handler = new Handler()
    {
        int i = 0;
        @Override
        public void handleMessage(Message msg) {

            if(msg.what == 0x123)
            {
                i++;
                move(i % 5 );
            }
            super.handleMessage(msg);
        }
    };
    void move(int z)
    {
        Drawable picA = getResources().getDrawable(R.drawable.g1);
        Drawable picB = getResources().getDrawable(R.drawable.g2);
        Drawable picC = getResources().getDrawable(R.drawable.g3);
        Drawable picD = getResources().getDrawable(R.drawable.g4);
        Drawable picE = getResources().getDrawable(R.drawable.g5);
        switch(z)
        {
            case 0:
                frame.setForeground(picA);
                break;
            case 1:
                frame.setForeground(picB);
                break;
            case 2:
                frame.setForeground(picC);
                break;
            case 3:
                frame.setForeground(picD);
                break;
            case 4:
                frame.setForeground(picE);
                break;
        }
    }
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_u_c3);

        frame = (FrameLayout) findViewById(R.id.myframe);

        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {

                handler.sendEmptyMessage(0x123);
            }
        }, 0,170);
    }
    public void OnClick(View v)
    {
        if(v.getId()==R.id.ret3)
        {
            Intent intent=new Intent();
            ComponentName cname=new ComponentName(this,MainActivity.class);
            intent.setComponent(cname);
            startActivity(intent);
        }
    }

}